package com.ayu.shortlink.admin.controller;

import com.ayu.shortlink.admin.common.convention.result.Result;
import com.ayu.shortlink.admin.common.convention.result.Results;
import com.ayu.shortlink.admin.remote.dto.ShortLinkActualRemoteService;
import com.ayu.shortlink.admin.remote.dto.req.RecycleBinRecoverDTO;
import com.ayu.shortlink.admin.remote.dto.req.RecycleBinRemoveReqDTO;
import com.ayu.shortlink.admin.remote.dto.req.RecycleBinSaveDTO;
import com.ayu.shortlink.admin.remote.dto.req.ShortLinkRecycleBinPageReqDTO;
import com.ayu.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import com.ayu.shortlink.admin.service.RecycleBinService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 后管回收站控制器
 */
@RestController(value = "recycleBinControllerByAdmin")
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleBinService recycleBinService;
    private final ShortLinkActualRemoteService shortLinkActualRemoteService;
    /**
     * 后管将短链接添加至回收站
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/save")
    public Result<Void> save(@RequestBody RecycleBinSaveDTO requestParam){
        shortLinkActualRemoteService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 后管分页查询回收站短链接
     */
    @GetMapping("/api/short-link/admin/v1/recycle-bin/page")
    public Result<Page<ShortLinkPageRespDTO>> pageReCycleBinShortLink(ShortLinkRecycleBinPageReqDTO requestParam){
        return recycleBinService.pageReCycleBinShortLink(requestParam);
    }

    /**
     * 恢复回收站短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> recover(@RequestBody RecycleBinRecoverDTO requestParam){
        shortLinkActualRemoteService.recover(requestParam);
        return Results.success();
    }

    /**
     * 删除回收站短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/remove")
    public Result<Void> remove(@RequestBody RecycleBinRemoveReqDTO requestParam){
        shortLinkActualRemoteService.remove(requestParam);
        return Results.success();
    }
}
